package com.ysxsoft.wdg.base;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import com.ysxsoft.wdg.MyApplication;
import com.ysxsoft.wdg.net.ApiHelper;
import com.ysxsoft.wdg.util.ScreenUtils;
import com.ysxsoft.wdg.util.statusbar.StatusBarUtil;
import com.zhy.http.okhttp.OkHttpUtils;

import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 */
@SuppressLint("Registered")
public abstract class BaseActivity extends AppCompatActivity {
    protected String TAG = this.getClass().getSimpleName();
    protected Context mContext;
    private Unbinder mUnbinder;
    protected ApiHelper mApiHelper;
    protected View mRootView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ScreenUtils.setCustomDensity(this, getApplication());
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        StatusBarUtil.setTranslucentStatus(this,true);
        setContentView(getLayoutId());
        mRootView = View.inflate(this,getLayoutId(),null);
        mUnbinder = ButterKnife.bind(this);
        mContext = this;
        mApiHelper = new ApiHelper();
        MyApplication.getInstance().addActivity(this);
        initData();
        setListener();
    }

    /**
     * 布局id
     */
    protected abstract int getLayoutId();

    protected abstract void initData();

    protected abstract void setListener();



    @Override
    protected void onDestroy() {
        super.onDestroy();
        mUnbinder.unbind();
        MyApplication.getInstance().removeActivity(this);
        OkHttpUtils.getInstance().cancelTag(this);
    }

    public void initStatusBar(View topView,boolean isWhite) {
        int barHeight = ScreenUtils.getStatusBarHeight(this);
        ViewGroup.LayoutParams params = topView.getLayoutParams();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {//19   4.4
            params.height = barHeight;
            topView.setVisibility(View.VISIBLE);
            topView.setLayoutParams(params);
            if (isWhite){
                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {//23
                    topView.setBackgroundColor(Color.parseColor("#40000000"));
                }
            }
        } else {
            params.height = 0;
            topView.setVisibility(View.GONE);
        }
    }


}
